﻿using OAZCSharpSdk.OAZ.Plugin.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OAZCSharpSdk.OAZ.Plugin.Extensions;

namespace OAZCSharpSdk.OAZ.Plugin.Cache
{
    public static class GroupCache
    {
        public static Dictionary<long, List<Manager>> GroupManagers { get; set; }

        /// <summary>
        /// 初始化群管理
        /// </summary>
        /// <param name="GroupQQ">群号</param>
        public static void InitializeGroupManagers(long RobotQQ, long GroupQQ)
        {
            if (GroupManagers == null)
            {
                GroupManagers = new Dictionary<long, List<Manager>>();
            }
            if (!GroupManagers.ContainsKey(GroupQQ))
            {
                var json = OAZ.Api_GetManager(RobotQQ, GroupQQ);
                GroupManagers.Add(GroupQQ, json.JsonDeserialize<List<Manager>>());
            }
        }

        /// <summary>
        /// 是否管理员
        /// </summary>
        /// <param name="RobotQQ">机器人QQ</param>
        /// <param name="GroupQQ">群号</param>
        /// <param name="QQ"></param>
        /// <returns></returns>
        public static bool IsManager(long RobotQQ, long GroupQQ, long QQ)
        {
            InitializeGroupManagers(RobotQQ, GroupQQ);
            return GroupManagers.ContainsKey(GroupQQ) && GroupManagers[GroupQQ].Any(x => x.QQ == QQ);
        }
    }
}
